<?php
 if ( ! defined('BASEPATH')) exit('No direct script access allowed');
Class Coupon extends MY_Controller
{
    public function __construct()
    {
        parent::__construct();
        $this->data['controller'] = 'coupon';         
        $this->load->model('Mcoupon');
    }
    
    public function index()
    {
        die(json_encode($this->Mcoupon->getData()));
    }
    
    public function detail()
    {
        die(json_encode($this->Mcoupon->getDetail()));
    }
    
    public function reviewcoupon(){
        $coupon_id  = $this->getParamInt("coupon_id");
        $user_id    = $this->getParamInt("user_id");
        $name       = $this->getParamString("name");
        $star       = $this->getParamInt("star");
        $content    = $this->getParamString("content");
        die(json_encode($this->Mcontent->reviewCouponDB($coupon_id,$user_id,$name,$star,$content)));
    }
    
    public function getreview()
    {
        die(json_encode($this->Mcoupon->getReviewCoupon()));
    }
	
    public function getCodeCoupon(){
            $coupon_id = $this->getParamInt('coupon_id');
            $user_id = $this->getParamInt('user_id');
            die(json_encode($this->Mcoupon->getCodeCouponDb($user_id,$coupon_id)));
    }

    public function checkdelcouponuser(){
            die(json_encode($this->Mcoupon->checkDelCouponUser()));
    }
    
    /**
     * Search coupoun,incentive theo zone và keyword
     * Theo zone thì lọc theo title Coupoun và mới nhất lên đầu,member loc theo username,fullname ,email,mobile
     */
    public function searchCoupon()
    {
        $limit = $this->getParamInt("limit");
        $zone = $this->getParamInt("zone");
        $keyword = $this->getParamString("keyword");
        $pageCoupon = $this->getParamString("pagecoupon");
        $pageIncentive = $this->getParamString("pageincentive");        
        die(json_encode($this->Mcoupon->searchCouponDb($keyword,$limit,$pageCoupon,$pageIncentive,$zone)));
    }
    
    /**
     * Lấy coupoun theo zone
     */
    public function getCoupon(){
        $limit = $this->getParamInt("limit");
        $page = $this->getParamInt("page");
        $zone= $this->getParamInt("zone");
        die(json_encode($this->Mcoupon->getCouponDb($limit,$page,$zone)));
    }
    
    /**
     * Lấy hot coupon
     */
    public function hotCoupon(){
        $limit = $this->getParamInt("limit");
        $page = $this->getParamInt("page");
        $zone= $this->getParamInt("zone");
        die(json_encode($this->Mcoupon->hotCouponDb($limit,$page,$zone)));
    }
    
    /**
     * check code coupon đã active,nhận ...
     */
    public function checkCodeCoupon(){
        $coupon_id = $this->getParamInt('coupon_id');
        $user_id = $this->getParamInt('user_id');
        die(json_encode($this->Mcoupon->checkCodeCouponDb($user_id,$coupon_id)));
    }
    /**
     * Lay coupon cua user
     */
    public function myCoupon(){
        $user_id=$this->getParamInt('user_id');
        $limit = $this->getParamInt("limit");
        $page = $this->getParamInt("page");
        die(json_encode($this->Mcoupon->myCouponDb($user_id,$limit,$page)));
    }
    
    /**
     * Xóa coupon
     */
    public function deleteCoupon(){
        $coupon_id = $this->getParamInt('coupon_id');
        $user_id = $this->getParamInt('user_id');
        die(json_encode($this->Mcoupon->deleteCouponDb($user_id, $coupon_id)));
    }
    
     /**
     *Lấy địa chỉ từ string nhà hàng
     */
    public function addressRes(){
        $stringRes = $this->getParamString('restaurant');
        $zone = $this->getParamInt('zone');
        die(json_encode($this->Mcoupon->addressResDb($stringRes,$zone)));
    }
    
    public function addressMycoupon(){
        $user_id = $this->getParamString('user_id');
//        $zone = $this->getParamInt('zone');
        die(json_encode($this->Mcoupon->addressMycouponDb($user_id)));
    }
    
    public function getCouponWicity(){
        $code_coupon=$this->getParamString("code_coupon");
        die(json_encode($this->Mcoupon->getCouponWicityDb($code_coupon)));
    }
}
